package activity.setting;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.hichip.campro.R;
import base.HiActivity;
import common.TitleView;

public class AlarmVoiceTypeActivity extends HiActivity implements OnClickListener {
	private TitleView title;
	private RelativeLayout  rl_alarm;//警号
	private RelativeLayout  rl_barking;//犬吠
	private int mVoiceType;

	private ImageView iv_alarm,iv_barking;




	@Override
	protected int setLayoutId() {
		return R.layout.activity_alarm_voice_type;
	}

	@Override
	protected void init(@Nullable Bundle savedInstanceState) {
		getIntentData();
		initView();
		setOnListeners();
	}

	private void getIntentData() {
		mVoiceType=getIntent().getIntExtra("mVoiceType", 0);
	}

	private void setOnListeners() {
		rl_alarm.setOnClickListener(this);
		rl_barking.setOnClickListener(this);
	}

	private void initView() {
		title=(TitleView) findViewById(R.id.title);
		title.setButton(TitleView.NAVIGATION_BUTTON_LEFT);
		title.setTitle(getString(R.string.alarm_sound_type_));
		title.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
			@Override
			public void OnNavigationButtonClick(int which) {
				switch (which) {
					case TitleView.NAVIGATION_BUTTON_LEFT:
						finish();
						break;
				}

			}
		});

		rl_barking=(RelativeLayout) findViewById(R.id.rl_barking);
		rl_alarm=(RelativeLayout) findViewById(R.id.rl_alarm);

		iv_alarm=(ImageView) findViewById(R.id.iv_alarm);
		iv_barking=(ImageView) findViewById(R.id.iv_barking);

		if(mVoiceType==0){
			iv_alarm.setVisibility(View.VISIBLE);
			iv_barking.setVisibility(View.GONE);
		}else {
			iv_alarm.setVisibility(View.GONE);
			iv_barking.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.rl_alarm:
				iv_barking.setVisibility(View.GONE);
				iv_alarm.setVisibility(View.VISIBLE);

				Intent intent=new Intent();
				intent.putExtra("mVoiceType", 0);
				setResult(RESULT_OK,intent);
				finish();
				break;
			case R.id.rl_barking:
				iv_barking.setVisibility(View.VISIBLE);
				iv_alarm.setVisibility(View.GONE);

				intent=new Intent();
				intent.putExtra("mVoiceType", 1);
				setResult(RESULT_OK,intent);
				finish();
				break;
		}

	}



}
